using Microsoft.SqlServer.Management.SqlManagerUI;
using System;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Windows.Forms;

namespace Microsoft.SqlServer.Tools.PublishWizard.CommandLine
{
	public sealed class Program
	{
		private Program()
		{
		}

		[STAThread]
		public static int Main(string[] args)
		{
			int num = args.Length;
			if (num > 0)
			{
				try
				{
					if (string.Compare(args[0], "GUI", StringComparison.OrdinalIgnoreCase) == 0 && num > 1)
					{
						string connectionString = string.Join(" ", args, 1, args.Length - 1);
						Program.SetupGUI();
						Application.Run(new GenScriptWizForm(null, new ServiceContainer(), connectionString));
						return 0;
					}
					string text = string.Format(CultureInfo.CurrentCulture, CommandLineResources.StandardHeader, new object[]
					{
						Assembly.GetExecutingAssembly().GetName().Version.ToString()
					});
					text = text.Replace("\\n", "\n");
					Console.WriteLine(text);
					CommandLineManager commandLineManager = new CommandLineManager();
					int result = commandLineManager.ParseAndExecuteArguments(args);
                    return result;
				}
				catch (Exception)
				{
					int result = 7;
					return result;
				}
			}
			Program.SetupGUI();
			Application.Run(new GenScriptWizForm(null, new ServiceContainer()));
			return 0;
		}

		internal static void SetupGUI()
		{
			UnsafeNativeMethods.FreeConsole();
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
		}
	}
}
